package com.xxxx.server.controller;


import com.xxxx.server.pojo.AdminInfo;
import com.xxxx.server.pojo.PassInfo;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IAdminService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private IAdminService adminService;

    /**
     * 修改个人中心用户信息
     */
    @PutMapping("/info")
    public RespBean updateAdmin(@RequestBody AdminInfo adminInfo){

        return adminService.updateAdmin(adminInfo);
    }

    /**
     * 修改密码
     */
    @PutMapping("/pass")
    public RespBean updatePass(@RequestBody PassInfo passInfo){

        return adminService.updatePass(passInfo);
    }

    /**
     * 上传头像
     */
    @PostMapping("/userface")
    public Map<String, Object> uploadFile(@RequestParam("id") Integer id, @RequestParam("file")MultipartFile file){
        // 获取上传文件
        // 返回上传到oss的路径
        String url = adminService.uploadFileAvatar(file,id);

        Map<String, Object> map = new HashMap<>();

        map.put("code","200");
        map.put("msg", "文件上传成功");
        map.put("url", url);

        return map;
    }
}
